function parseDisableClassNames()
{
  var elems = $$('select.sf_admin_disabled_input', 'input.sf_admin_disabled_input', 'textarea.sf_admin_disabled_input');
  for (var i=0; i<elems.length; i++)
  {
    elems[i].removeClassName('sf_admin_disabled_input');
    elems[i].disable();
  }
}

function disableFurtherSubmit(form)
{
  elems = $(form).getInputs('submit');
  for (var i=0;i<elems.length;i++)
  {
    elems[i].disable();
  }
  return true;
}


Event.observe(window, 'load', parseDisableClassNames);


function getNextFormElement(current_element)
{
  var next_row = current_element.closest('.sf_admin_form_row').next('.sf_admin_form_row');
  if (next_row.size() > 0)
  {
    var next_element = next_row.find('input');
    if (next_element.size() == 0)
    {
      next_element = next_row.find('select');
      if (next_element.size() == 0)
      {
        next_element = next_row.find('textarea');
      }
    }

    if (next_element.size() > 0)
    {
      return next_element;
    }
  }

  return;
}

//  Prevent form submission on <ENTER> keypress. Instead, switch to the next form element, if any.
jQuery(function() {
  jQuery('#sf_admin_edit_form input').keypress(function (e) {
    if (e.which == 13)
    {
      var next_element = getNextFormElement(jQuery(this));
      if (next_element)
      {
        next_element.focus();
      }
      else
      {
        jQuery('#sf_admin_edit_form input[type=submit]').focus();
      }

      return false;
    }
  });
});
